<template>
  <a-modal
    :visible="visible"
    :width="1000"
    okText="提交"
    cancelText="取消"
    :title="title"
    :destroyOnClose="true"
    :maskClosable="false"
    @cancel="closeModal()"
    :keyboard="false">
    <a-form :label-col="{ span: 7 }"
      :wrapper-col="{ span: 12 }">
      <a-form-item>
        <template slot="label">
          <span class="ant-form-item-required">
            产品分类
          </span>
        </template>
        <span>{{seriesParams.seriesClassificationName}}</span>
        <!-- <a-button type="primary" @click="handleAddClassify">增加分类归类</a-button>
        <div v-for="(item,index) in addClassifyList" :key="index">
          <a-space>
            <a-cascader
              :options="classifyList"
              :allowClear="true"
              style="width:240px;"
              v-model="item.value"
              placeholder="请选择产品分类"/>
            <a-icon class="dynamic-delete-button"
              type="minus-circle-o"
              @click="handleRemoveClassify(index)"/>
          </a-space>
        </div> -->
      </a-form-item>
      <a-form-item>
        <template slot="label">
          <span class="ant-form-item-required">
            产品名称
          </span>
        </template>
        <a-input
          autocomplete="off"
          v-model="productName"
          :disabled="disabled"
          :maxLength="32"
          placeholder="请输入产品名称，限32位汉字以内"
        />
      </a-form-item>
      <a-form-item>
        <template slot="label">
          <span class="ant-form-item-required">
            产品主图片
          </span>
        </template>
          <a-space class="main_picture" >
              <ImageUpload
                v-model="largeScreenPicture"
                :disabled="disabled"
                uploadTextHtml="大屏APP封面图<br/>建议尺寸：<br/>540*540像素"></ImageUpload>
              <ImageUpload
                v-model="appPicture"
                :disabled="disabled"
                uploadTextHtml="手机APP封面图<br/>建议尺寸：540*540像素"></ImageUpload>
              <ImageUpload
                v-model="appletPicture"
                :disabled="disabled"
                uploadTextHtml="小程序封面图<br/>建议尺寸：690*300像素"></ImageUpload>
          </a-space>
          <div>
            <a-space align="start" class="upload_detail">
                <!-- <ImageUploadList
                  :limit="9"
                  :multiple="true"
                  :isCustomBtn="true"
                  @change="handleDetailChange">
                  <a-button type="primary"> 上传详情图片 </a-button>
                </ImageUploadList>
                *建议尺寸：1280*670像素 -->
                <ImageUploadList
                  :limit="1000"
                  :multiple="true"
                  :disabled="disabled"
                  uploadTextHtml="轮播图建议尺寸1280*760像素或等比例大小，图片大小在2M以内"
                  v-model="productDetailsList"
                  @urls="handleFilesChange">
                </ImageUploadList>
            </a-space>
          </div>
      </a-form-item>
      <a-form-item label="全景图">
        <a-radio-group :options="yesNo" :disabled="disabled"
          v-model="enablePanorama"></a-radio-group>
      </a-form-item>
      <a-form-item label="产品链接">
        <!-- <a href="javascript:;" @click="linkAddressModalVisible=true">链接地址</a>
        <a-modal
          title="产品链接"
          :visible="linkAddressModalVisible"
          @ok="linkAddressModalVisible=false"
          @cancel="linkAddressModalVisible=false"
        >
          <a-input type="text"
            v-model="productUrl"/>
        </a-modal> -->
        <a-input type="text" placeholder="请输入产品VR链接" :disabled="disabled" v-model="productUrl"/>
      </a-form-item>
      <a-form-item label="产品规格">
        <div class="product_spec table">
          <div class="tbody">
            <div class="tr" v-for="(item,index) in productSpec" :key="index">
              <div class="th">
                <input type="text" maxlength="10" v-model="item.left.value" :placeholder="item.left.placeholder" @change="handleChangeProductSpec"/>
              </div>
              <div class="td">
                <input type="text" maxlength="10" v-model="item.right.value" :placeholder="item.right.placeholder" @change="handleChangeProductSpec"/>
              </div>
              <div class="icon">
                <a-icon class="dynamic-delete-button" :disabled="disabled"
                  type="minus-circle-o" @click="handleRemoveProductSpec(index)"/>
              </div>
            </div>
          </div>
          <div class="tfoot">
            <div class="tr">
              <div class="td">
                <a href="javascript:;" @click="handleAddProductSpec">点击增加规格</a>
              </div>
            </div>
          </div>
        </div>
      </a-form-item>
      <a-form-item label="产品简介">
        <a-input placeholder="请输入产品介绍，限38汉字以内"
         v-model="productIntroduction" :maxLength="38" :disabled="disabled"></a-input>
        <!-- <tinymce-editor v-model="productIntroduction"></tinymce-editor> -->
      </a-form-item>
      <a-form-item>
         <template slot="label">
          <span class="ant-form-item-required">
            排序
          </span>
        </template>
        <a-input type="number"
          v-model="sort"
          :disabled="disabled"
         placeholder="请输入4位以内的整数"
style="width:160px"/>
      </a-form-item>
      <a-form-item>
        <template slot="label">
          <span class="ant-form-item-required">
            是否显示
          </span>
        </template>
        <a-radio-group :options="statusList" :disabled="disabled"
          v-model="showStatus"></a-radio-group>
      </a-form-item>
      <a-form-item>
        <template slot="label">
          <span class="ant-form-item-required">
            设为新品
          </span>
        </template>
        <a-radio-group :options="yesNo" :disabled="disabled"
          v-model="enableNew"></a-radio-group>
      </a-form-item>
      <a-form-item>
        <template slot="label">
          <span class="ant-form-item-required">
            展示平台
          </span>
        </template>
        <a-checkbox-group
          :options="platformList"
          :disabled="disabled"
          v-model="showPlatform">
        </a-checkbox-group>
      </a-form-item>
      <a-form-item label="报价">
        <a-radio-group
          :options="statusList"
          :disabled="disabled"
          v-model="quotedPrice">
        </a-radio-group>
        <template  v-if="quotedPrice">
          <div>
            <a-button type="primary" :disabled="disabled" @click="handleAddOfferAttr">添加报价属性</a-button>
          </div>
          <template v-if="quotationAttrList.length>0">
            <table class="table2 quotationAttr"
              v-for="(item,index) in quotationAttrList" :key="index">
              <tbody>
                <tr v-for="(item2,index2) in item.options" :key="index2">
                  <td :rowspan="item.options.length+1" v-if="index2==0">
                    <a-select style="width:100px;"
                      :options="quotationAttrNameList"
                      placeholder="选择属性名称"
                      v-model="item.id"
                      @change="handleChangeQuotationAttr"
                    ></a-select>
                  </td>
                  <td>单价</td>
                  <td>
                    <input type="number" placeholder="数值" v-model="item2.unitPrice" @change="handleChangeQuotationAttr"/>
                  </td>
                  <td>属性值范围</td>
                  <td>
                    <input type="number" placeholder="数值" v-model="item2.minNumber" @change="handleChangeQuotationAttr"/>
                    -
                    <input type="number" placeholder="数值" v-model="item2.maxNumber" @change="handleChangeQuotationAttr"/>
                    <a-icon class="dynamic-delete-button" type="minus-circle-o" @click="handleRemoveQuoteAttr(index,index2)"/>
                  </td>
                </tr>
                <tr>
                  <td colspan="4">
                    <a href="javascript:;" @click="handleAddQuoteAttr(index)">添加属性区间</a>
                  </td>
                </tr>
              </tbody>
            </table>
          </template>
        </template>
      </a-form-item>
      <a-form-item>
         <template slot="label">
            <span class="ant-form-item-required">
              产品卖点
            </span>
          </template>
          <a-button type="primary" :disabled="disabled" @click="handleAddSellpoint">添加共用详情</a-button>
          <ul>
            <li v-for="(item,index) in addSellpointList" :key="index">
              <a-select v-model="item.value" :disabled="disabled" style="width:240px;" @change="handleChangeSellpoint(item,index)">
                <a-select-option v-for="(item,index) in sellpointList" :key="index" :value="item.pointType+'_'+item.id">{{item.typeName}} / {{item.pointName}}</a-select-option>
              </a-select>
              <a-icon class="dynamic-delete-button remove_ellpoint"
                  type="minus-circle-o" @click="handleRemoveSellpoint(item,index)"/>
            </li>
          </ul>
      </a-form-item>  
    </a-form>
    <template slot="footer">
      <a-space>
        <a-button key="back" @click="closeModal()">取消</a-button>
        <a-button type="primary" :disabled="disabled" :loading="confirmLoading" @click="handleSubmit">保存</a-button>
      </a-space>
    </template>
  </a-modal>
</template>

<script>
import deepCopy from '@/utils/deepCopy'
import { showPlatformList, showStatusList, showSpecList, yesOrNo } from '@/utils/dictData'
import ImageUpload from '@/components/antBase/ImageUpload'
import ImageUploadList from '@/components/form/UploadImage';

import {createOptionsByDict,findDictListByType,findDictNameByValue} from '@/utils/dict';

export default {
  components: {
    ImageUpload,
    ImageUploadList
  },
  name: 'NewProducts',
  props: {
    record: {
      type: Object,
      default () {
        return {}
      }
    },
    visible: {
      type: Boolean,
      default: false
    },
    seriesParams: {
      type: Object,
      default () {
        return {}
      }
    },
    seriesType: {
      type: [String, Number]
    }
  },
  computed: {
    title () {
      return this.record.id ? (this.seriesType == 1 ? '查看产品' : '修改产品') : '新增产品'
    },
    disabled() {
      return this.seriesType == 1;
    }
  },
  data () {
    return {
      // 产品分类
      classifyList: [],
      // 添加分类归类
      addClassifyList: [],
      // 产品名称
      productName: '',
      // 是否全景图
      enablePanorama: 0,
      // 产品链接
      productUrl: '',
      //linkAddressModalVisible: false,
      // 产品规格
      productSpec: JSON.parse(JSON.stringify(showSpecList)),
      // 产品简介
      productIntroduction: '',
      // 排序
      sort: 0,
      // 显示状态
      statusList: showStatusList,
      showStatus: 1,
      // 设为新品
      yesNo: yesOrNo,
      enableNew: 0,
      // 展示平台
      platformList: showPlatformList,
      showPlatform: [],
      // 报价选择属性名
      quotationAttrNameList: [],
      // 上传详情图片
      productDetailsList: '',
      // 产品主图片
      largeScreenPicture: '', // 大屏APP封面图
      appPicture: '', // APP封面图
      appletPicture: '', // 小程序封面图
      isUploadDetailMessage: false,
      // 是否报价
      quotedPrice: 1,
      // 报价属性列表
      quotationAttrList: [],
      formatQuotationAttrList: [],
      // submitQuotationAttrList:[],//单位转换之后的数据
      // 图库产品
      productSpecList: [],
      //卖点列表
      sellpointList:[],//
      addSellpointList:[],//添加的卖点
      //allSellpointTypeList:[],//所有卖点类型
      // 提交表单数据
      formData: {
        galleryClassificationIdList: [], // 图库分类id集合
        galleryProductName: '', //	图库产品名称
        largeScreenPicture: '', // 大屏APP封面图
        appPicture: '', // APP封面图
        appletPicture: '', // 小程序封面图
        galleryProductPictures: [], // 图库产品图片url集合,
        enablePanorama: 0, // 是否全景图（0.,否 1.是）
        galleryProductUrl: '', // 图库产品链接
        galleryProductSpecList: [], // 图库产品规格属性集合
        galleryProductDescribe: '', // 图库产品简介
        sort: 0, // 排序
        enableShow: '', // 是否展示（0.,否 1.是）
        enableNew: 0, // 设为新品（0.,否 1.是）
        exhibitionPlatform: '', // 展示平台 (多个平台用,隔开)
        quotedPrice: '', // 是否报价（0.,否 1.是）
        galleryQuotedPriceList: '', // 报价属性集合
      },
      confirmLoading: false
    }
  },
  watch: {
    visible (newVal) {
      this.resetData()
      if (newVal) {
        this.getClassifyList()
        this.getPaopertyList()
        this.getSellpointList();
        this.getDetail()
      }
    }
  },
  created () {
    this.resetData()
    this.getClassifyList()
    this.getPaopertyList()
    this.getSellpointList();
    this.getDetail()

    //this.allSellpointTypeList=createOptionsByDict('SELLING_POINT_TYPE');
    //console.log('findDictNameByValue',findDictNameByValue('SELLING_POINT_TYPE',1))
  },
  methods: {
    //卖点列表查询
    async getSellpointList(){
      let res=await this.$get('/sellpoint/list')
      if(res && res.returnCode=='1000'){
        this.sellpointList=res.dataInfo || [];
        // this.sellpointList.forEach(item=>{
        //   item.pointTypeName=findDictNameByValue('SELLING_POINT_TYPE',item.pointType);
        // })
        console.log(' this.sellpointList', this.sellpointList)
      }
    },
    //产品卖点  切换验证
    handleChangeSellpoint(currentItem,currentIndex,isAutoClear=true){
      let result=this.addSellpointList.find((item,index)=>{
        //console.log("item.value.split('_')[0]===currentItem.value.split('_')[0]",item.value.split('_')[0],currentItem.value.split('_')[0],currentIndex,index)
        if(!item.value || !currentItem.value){
          return false;
        }
        return item.value.split('_')[0]===currentItem.value.split('_')[0] && currentIndex!==index;
      })
      if(result!=undefined){
        if(isAutoClear){
          this.addSellpointList[currentIndex].value='';
        }
        this.$message.error('一个详情类型只能选择一次')
        return 2;
      }
    },
    //产品卖点  添加
    handleAddSellpoint(){
      if(this.addSellpointList.length>=4){
        return this.$message.error('详情最多添加4个')
      }
      this.addSellpointList.push({
        value:'',
      });
    },
    getAllSellpointIds(){
      return this.addSellpointList.map(item=>{
        return item.value.split('_')[1];
      }).filter(item=>item);
    },
    //产品卖点  移出
    handleRemoveSellpoint(item,index){
      this.addSellpointList.splice(index,1);
    },
    //数据分组
    dataItemGroup(arr, key) {
        let newArr = [],
            types = {},
            newItem, i, j, cur;
        for (i = 0, j = arr.length; i < j; i++) {
            cur = arr[i];
            if (!(cur[key] in types)) {
                types[cur[key]] = { type: cur[key], data: [] };
                newArr.push(types[cur[key]]);
            }
            types[cur[key]].data.push(cur);
        }
        return newArr;
    },
    //表格内输入值是否已包含
    checkTableRangItemInclude(dataGroups=[]){
      for(let i=0;i<dataGroups.length;i++){
        //单价是否存在重复
        let priceArr=[];
        for(let j=0;j<dataGroups[i].data.length;j++){
          priceArr.push(parseInt(dataGroups[i].data[j].unitPrice));
        }
        console.log('priceArr,Array.from(new Set(priceArr))',priceArr,Array.from(new Set(priceArr)))
        if(priceArr.length!=Array.from(new Set(priceArr)).length){
          return 1;
        }

        //属性值范围是存在冲突
        for(let j=0;j<dataGroups[i].data.length;j++){ 
          let copyData=deepCopy(dataGroups[i].data)||[];
          copyData.splice(j,1);
          let startMin=parseInt(dataGroups[i].data[j].minNumber) || 0;
          let startMax=parseInt(dataGroups[i].data[j].maxNumber) || 0;
          for(let m=0;m<copyData.length;m++){
            console.log(copyData[m].unitPrice)
            console.log(startMin,startMax,parseInt(copyData[m].minNumber),parseInt(copyData[m].maxNumber))
            console.log(parseInt(Math.min(startMax,copyData[m].maxNumber)),parseInt(Math.max(startMin,copyData[m].minNumber)))
            if(Math.min(startMax,parseInt(copyData[m].maxNumber))>=Math.max(startMin,parseInt(copyData[m].minNumber))){
              return 2;
            }
          }
        }
      }
    },
    resetData () {
      console.log('清空')
      this.addClassifyList = []
      this.productName = ''
      this.largeScreenPicture = ''// 大屏APP封面图
      this.appPicture = ''// APP封面图
      this.appletPicture = ''// 小程序封面图
      this.productDetailsList = ''
      this.enablePanorama = 0
      this.productUrl = ''
      this.productSpec = JSON.parse(JSON.stringify(showSpecList))
      this.productIntroduction = ''
      this.sort = 0
      this.showStatus = 1
      this.enableNew = 0
      this.showPlatform = []
      this.quotedPrice = 1
      this.quotationAttrList = []
      this.addSellpointList=[];
    },
    formatClassifyList (data) {
      let tmpData = []
      for (let i = 0; i < data.length; i++) {
        let item = {
          label: data[i].classificationName,
          value: data[i].id
        }
        if (data[i].children && data[i].children.length > 0) {
          item['children'] = this.formatClassifyList(data[i].children)
        }
        tmpData.push(item)
      }
      console.log('tmpData', tmpData)
      return tmpData
    },
    // 产品分类
    async getClassifyList () {
      let res = await this.$get('/gallery/classification/list')
      console.log(res)
      if (res && res.returnCode == 1000 && res.dataInfo) {
        let tmpData = this.formatClassifyList(res.dataInfo || [])
        this.classifyList = tmpData.filter(item => {
          return item.children && item.children.length > 0
        })
        console.log('this.classifyList', this.classifyList)
      }
    },
    // 报价属性名
    async getPaopertyList () {
      let res = await this.$get('/quoted/property/list')
      if (res && res.returnCode == 1000 && res.dataInfo) {
        let tmpData = []
        res.dataInfo.forEach(item => {
          tmpData.push({
            label: item.quotedName,
            value: item.id
          })
        })
        this.quotationAttrNameList = tmpData
      }
    },
    // 格式化产品属性
    formatQuotedPriceListData (arr) {
      var map = {}
      var dest = []
      for (var i = 0; i < arr.length; i++) {
        var ai = arr[i]
        if (!map[ai.quotedPriceId]) {
          dest.push({
            id: ai.quotedPriceId,
            options: [ai]
          })
          map[ai.quotedPriceId] = ai
        } else {
          for (var j = 0; j < dest.length; j++) {
            var dj = dest[j]
            if (dj.id === ai.quotedPriceId) {
              dj.options.push(ai)
              break
            }
          }
        }
      }
      return dest
    },
    formatGalleryClassificationList (data) {
      let tmpData = []
      data.forEach(item => {
        if (item) {
          let arr = item.split(',')
          if (arr.length > 0) {
            arr.splice(0, 1)
            let tmpData2 = []
            arr.forEach(item => {
              tmpData2.push(item.trim())
            })
            tmpData.push(tmpData2)
          }
        }
      })
      return tmpData
    },
    //卖点回显结果处理，格式：卖点类型_卖点名称
    formatSellPoint(sellPointIdsStr=''){
      //let sellPointIdsStr = tmpObj.sellPointIds || '';
      if(sellPointIdsStr){
        let sellPointIds=sellPointIdsStr.split(','); 
        sellPointIds.forEach(item=>{
          let pointType='';
          this.sellpointList.forEach(item2=>{
            if(item==item2.id){
              pointType=item2.pointType;
            }
          })
          this.addSellpointList.push({
            value:pointType+'_'+item
          });
        })
      }
    },
    async getDetail () {
      let id = this.record.id
      if (!id) {
        return
      }
      let res = await this.$get('/gallery/product/query', { id })
      if (res && res.returnCode == 1000) {
        let tmpObj = res.dataInfo
        if (tmpObj.galleryClassificationList &&
          tmpObj.galleryClassificationList.length > 0) {
            console.log('tmpObj.galleryClassificationList', tmpObj.galleryClassificationList)
          tmpObj.galleryClassificationList = this.formatGalleryClassificationList(tmpObj.galleryClassificationList)
          this.addClassifyList = []
          tmpObj.galleryClassificationList.forEach(item => {
            this.addClassifyList.push({
              value: item || []
            })
          })
        }
        console.log('this.addClassifyList', this.addClassifyList)
        this.productName = tmpObj.galleryProductName
        this.largeScreenPicture = tmpObj.largeScreenPicture
        this.appPicture = tmpObj.appPicture
        this.appletPicture = tmpObj.appletPicture
        this.enablePanorama = tmpObj.enablePanorama
        this.productUrl = tmpObj.galleryProductUrl
        this.productIntroduction = tmpObj.galleryProductDescribe
        this.sort = tmpObj.sort
        this.showStatus = tmpObj.enableShow
        this.enableNew = tmpObj.enableNew
        this.quotedPrice = tmpObj.quotedPrice
        this.productDetailsList = tmpObj.galleryProductPictures
        this.showPlatform = tmpObj.exhibitionPlatform && tmpObj.exhibitionPlatform.split(',').map(item => {
          return parseInt(item)
        })
        let quotationAttrList = this.quotationAttrListFenToYuan(deepCopy(tmpObj.galleryQuotedPriceList || []))
        this.quotationAttrList = this.formatQuotedPriceListData(quotationAttrList)
        this.handleChangeQuotationAttr()

        this.formatSellPoint(tmpObj.sellPointIds);

        if (tmpObj.galleryProductSpecList && tmpObj.galleryProductSpecList.length > 0) {
          this.productSpec = []
          tmpObj.galleryProductSpecList.forEach(item => {
            this.productSpec.push({
              left: {
                placeholder: '请输入',
                value: item.specsName
              },
              right: {
                placeholder: '请输入',
                value: item.specsValue
              }
            })
          })
          this.handleChangeProductSpec()
        }
      }
    },
    // 添加分类归类
    handleAddClassify () {
      if (this.addClassifyList.length < 3) {
        this.addClassifyList.push({
          value: []
        })
      } else {
        this.$message.error('最多添加三个分类')
      }
    },
    // 移出分类归类
    handleRemoveClassify (index) {
      this.addClassifyList.splice(index, 1)
    },
    async handlePreview (file) {
      if (!file.url && !file.preview) {
        file.preview = await this.getBase64(file.originFileObj)
      }
      this.previewImage = file.url || file.preview
      this.previewVisible = true
    },
    getBase64 (img, callback) {
      const reader = new FileReader()
      reader.addEventListener('load', () => callback(reader.result))
      reader.readAsDataURL(img)
    },
    // 上传详情图片
    handleDetailChange (info) {
      // console.log('urls', info)
      // this.productDetailsList = info
    },
    handleFilesChange(urls){
      // this.productDetailsList = urls;
    },
    // 大屏APP封面图
    handleChange0 (info) {
      this.largeScreenPicture = info
    },
    // 手机APP封面图
    handleChange1 (info) {
      this.appPicture = info
    },
    // 小程序封面图
    handleChange2 (info) {
      this.appletPicture = info.file.response.url
    },
    beforeUpload (file) {
      const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'
      if (!isJpgOrPng) {
        this.$message.error('你只能上传png或jpg图片!')
      }
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('图像必须小于2MB！')
      }
      return isJpgOrPng && isLt2M
    },
    closeModal (freshTable) {
      // this.form.resetFields()
      this.resetData()
      this.$emit('cancel', freshTable)
    },
    // 添加产品规则
    handleAddProductSpec () {
      this.productSpec.push({
        left: {
          placeholder: '请输入',
          value: ''
        },
        right: {
          placeholder: '请输入',
          value: ''
        }
      })
    },
    handleRemoveProductSpec(index){
      this.productSpec.splice(index,1);
      this.handleChangeProductSpec();
    },
    handleChangeProductSpec () {
      let galleryProductSpecList = []
      this.productSpec.forEach(item => {
        if (item.left.value && item.right.value) {
          galleryProductSpecList.push({
            specsName: item.left.value,
            specsValue: item.right.value
          })
        }
      })
      this.productSpecList = galleryProductSpecList
    },
    // 添加报价属性
    handleAddOfferAttr () {
      this.quotationAttrList.push({
        id: '',
        options: [
          {
            unitPrice: '',
            minNumber: '',
            maxNumber: ''
          }
        ]
      })
    },
    // 添加属性区间
    handleAddQuoteAttr (index) {
      this.quotationAttrList[index].options.push({
        unitPrice: '',
        minNumber: '',
        maxNumber: ''
      })
    },
    //移出属性区间
    handleRemoveQuoteAttr(index,index2){
      this.quotationAttrList[index].options.splice(index2,1);
      console.log(this.quotationAttrList.length, this.quotationAttrList[index].options.length)
      if(this.quotationAttrList[index].options.length==0){
        this.quotationAttrList.splice(index,1);
      }
      this.handleChangeQuotationAttr();
    },
    // 报价属性监听
    handleChangeQuotationAttr () {
      let tmpData = []
      this.quotationAttrList.forEach(item => {
        let tmpOption = []
        if (item.options && item.options.length > 0) {
          item.options.forEach(item2 => {
            if (item.id && item2.unitPrice && item2.minNumber && item2.maxNumber) {
              tmpOption.push({
                quotedPriceId: item.id,
                unitPrice: item2.unitPrice,
                minNumber: item2.minNumber,
                maxNumber: item2.maxNumber
              })
            }
          })
        }
        tmpData.push(...tmpOption)
      })
      this.formatQuotationAttrList = tmpData
    },
    // 报价属性单位换算=>元转分
    quotationAttrListYuanToFen (data = []) {
      let tmpData = []
      data.forEach(item => {
        tmpData.push({
          quotedPriceId: item.quotedPriceId,
          unitPrice: parseInt((item.unitPrice || 0) * 10 * 10),
          minNumber: parseInt(item.minNumber),
          maxNumber: parseInt(item.maxNumber)
        })
      })
      return tmpData
      // this.submitQuotationAttrList = tmpData;
    },
    // 报价属性单位换算=>分转元
    quotationAttrListFenToYuan (data = []) {
      let tmpData = []
      data.forEach(item => {
        tmpData.push({
          quotedPriceId: item.quotedPriceId,
          unitPrice: ((item.unitPrice || 0) / 100).toFixed(2),
          minNumber: item.minNumber,
          maxNumber: item.maxNumber
        })
      })
      return tmpData
      // this.quotationAttrList=tmpData;
    },
    // 提交
    handleSubmit () {
      // let addClassifyList = this.addClassifyList.map(item => {
      //   return item.value.join(',')
      // }).filter(item => {
      //   return item
      // })
      // // addClassifyList=Array.from(new Set(addClassifyList));
      // if (!addClassifyList.length) {
      //   this.$message.error('请选择产品分类')
      //   return
      // }
      // if (addClassifyList.length > 3) {
      //   this.$message.error('最多添加三个分类')
      //   return
      // }
      // console.log(Array.from(new Set(addClassifyList)).length, addClassifyList.length)
      // if (Array.from(new Set(addClassifyList)).length != addClassifyList.length) {
      //   this.$message.error('分类存在重复')
      //   return
      // }
      if (!this.productName) {
        this.$message.error('请输入产品名称，限32位汉字以内')
        return
      }
      if (!this.largeScreenPicture) {
        this.$message.error('请上传大屏APP封面图')
        return
      }
      if (!this.appPicture) {
        this.$message.error('请上传APP封面图')
        return
      }
      if (!this.appletPicture) {
        this.$message.error('请上传小程序封面图')
        return
      }
      if (!this.sort && this.sort !== 0) {
        this.$message.error('请输入排序')
        return
      }
      if (this.showStatus === '') {
        this.$message.error('请选择是否显示')
        return
      }
      if (this.enableNew === '' || this.enableNew === undefined || this.enableNew === null) {
        this.$message.error('请选择是否设为新品')
        return
      }
      if (!this.showPlatform.length) {
        this.$message.error('请选择展示平台')
        return
      }
      if(this.quotedPrice==1 && this.formatQuotationAttrList.length==0){
        this.$message.error('请添加报价属性')
        return
      }
      if(this.quotedPrice==1 && this.formatQuotationAttrList.length>0){
        //重置报价类型
        let dataGroups=this.dataItemGroup(this.formatQuotationAttrList,'quotedPriceId');
        console.log(dataGroups)
        let result=this.checkTableRangItemInclude(dataGroups);
        if(result==1){
          this.$message.error('报价属性单价存在冲突!')
          return;
        }
        else if(result==2){
          this.$message.error('报价属性属性值范围存在冲突!')
          return;
        }
      }
      let sellPointIds=this.getAllSellpointIds();
      if(sellPointIds.length==0){
        this.$message.error('请选择产品卖点!')
        return;
      }
      for(let i=0;i<this.addSellpointList.length;i++){
        let item=this.addSellpointList[i];
        if(this.handleChangeSellpoint(item,i,false)==2){
          return;
        }
      }
      // console.log('this.submitQuotationAttrList',this.submitQuotationAttrList)
      this.formData = {
        // galleryClassificationIdList: addClassifyList, // 图库分类id集合
        seriesId: this.seriesParams.id, //套系id
        galleryClassificationIdList: this.seriesParams.treePaths, // 图库分类id集合
        galleryProductName: this.productName, //	图库产品名称
        largeScreenPicture: this.largeScreenPicture, // 大屏APP封面图
        appPicture: this.appPicture, // APP封面图
        appletPicture: this.appletPicture, // 小程序封面图
        galleryProductPictures: this.productDetailsList, // 图库产品图片url集合,
        enablePanorama: this.enablePanorama, // 是否全景图（0.,否 1.是）
        galleryProductUrl: this.productUrl, // 图库产品链接
        galleryProductSpecList: this.productSpecList, // 图库产品规格属性集合
        galleryProductDescribe: this.productIntroduction, // 图库产品简介
        sort: this.sort, // 排序
        enableShow: this.showStatus, // 是否展示（0.,否 1.是）
        enableNew: this.enableNew, // 设为新品（0.,否 1.是）
        exhibitionPlatform: this.showPlatform.join(','), // 展示平台 (多个平台用,隔开)
        quotedPrice: this.quotedPrice, // 是否报价（0.,否 1.是）
        galleryQuotedPriceList: this.quotationAttrListYuanToFen(deepCopy(this.formatQuotationAttrList)), // 报价属性集合
        sellPointIds:sellPointIds.join(',')
      }
      if (this.record && this.record.id) {
        this.formData.id = this.record.id
      }
      console.log(this.formData)
      let add_url = '/gallery/product/add'
      let update_url = '/gallery/product/update'
      let url = this.record.id ? update_url : add_url
      this.confirmLoading = true;
      this.$post(url, this.formData).then(res => {
        if (res && res.returnCode === 1000) {
          this.$message.success('保存成功！')
          this.confirmLoading = false;
          this.closeModal(true)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
  ::-webkit-input-placeholder { /* WebKit browsers */
    color: #ccc;
    font-size: 14px;
  }
  input::-webkit-outer-spin-button,
  input::-webkit-inner-spin-button {
      -webkit-appearance: none;
  }
  input[type="number"]{
      -moz-appearance: textfield;
  }
  .avatar_img{
    max-width:104px;
  }
  .main_picture{
    /deep/ .ant-upload{
      width:104px!important;
      height:104px!important;
      .anticon {
        svg{
          font-size:24px;
          color:#016BFF;
        }
      }
      img{
        //display: block;
        max-width: 100%;
        max-height: 100%;
      }
      .ant-upload-text{
        font-size:12px;
      }
    }
  }
  .table{
    border-right: 1px solid #E6E6E6;
    border-bottom: 1px solid #E6E6E6;
    //border-radius: 4px;
    .tbody{
      .tr{
        display:flex;
        align-items: center;
        position: relative;
        .th,.td{
          border-top: 1px solid #E6E6E6;
          border-left: 1px solid #E6E6E6;
          padding:0 10px;
          white-space: nowrap;
          input[type=text],
          input[type=number]{
            border:none;
            outline:none;
            box-sizing: border-box;
            height:40px;
          }
          input[type=number]{
            line-height: 1;
          }
        }
        .th{
          input[type=text]{
            text-align: center;
          }
        }
        .td{
          flex:1;
          input[type=text]{
            width: 100%;
          }
        }
        .icon{
          position:absolute;
          right:-0.3rem;
        }
      }
    }
    .tfoot{
      .tr{
        .td{
          border-top: 1px solid #E6E6E6;
          border-left: 1px solid #E6E6E6;
          background:#F5F5F5;
          text-align: center;
          a{
            font-size:12px;
          }
        }
      }
    }
  }
  //报价
  .table2{
    border: 1px solid #E6E6E6;
    //border-radius: 4px;
    tbody{
      tr:last-child{
        text-align: center;
      }
      tr{
        th,td{
          border: 1px solid #E6E6E6;
          padding:0 10px;
          white-space: nowrap;
          position: relative;
          .dynamic-delete-button{
            position: absolute;
            right:-0.3rem;
            top:15px;
            cursor: pointer;
          }
          input[type=text],
          input[type=number]{
            border:none;
            outline:none;
            box-sizing: border-box;
            height:40px;
          }
          input[type=number]{
            line-height: 1;
          }
        }
        th{
          input[type=text]{
            text-align: center;
          }
        }
        // td{
        //   input[type=text]{
        //   }
        // }
      }
    }
    tfoot{
      td{
        background:#F5F5F5;
        text-align: center;
        a{
          font-size:12px;
        }
      }
    }
  }
  .quotationAttr{
    margin-bottom: 10px;
    /deep/ .ant-select-selection{
      border:none;
      outline:none;
    }
    .ant-select-open .ant-select-selection{
      box-shadow: none;
    }
    input{
      width:60px;
      text-align: center;
    }
    // display:flex;
    // .left{
    //   border-left:1px solid #E6E6E6;
    //   border-top:1px solid #E6E6E6;
    // }
    // .right{
    //   .row{
    //     border-top:1px solid #E6E6E6;
    //     .label{
    //       border-left:1px solid #E6E6E6;
    //     }
    //     .item{
    //       border-left:1px solid #E6E6E6;
    //       input{

    //       }
    //     }
    //   }
    // }
  }
  .remove_ellpoint{
    cursor: pointer;
    margin-left:10px;
  }
</style>
